From 8ecdc794ab848076dec43732c026ec77f3a87520 Mon Sep 17 00:00:00 2001 From: Ewan Mellor Date: Sat, 23 Dec 2006 11:24:10 +0000 Subject: [PATCH] Added I18N support for Xen-API error codes. Signed-off-by: Ewan Mellor --- tools/python/Makefile | 14 ++++- tools/python/xen/xm/XenAPI.py | 17 +++++- tools/python/xen/xm/main.py | 2 +- tools/python/xen/xm/messages/en/xen-xm.po | 67 +++++++++++++++++++++++ 4 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 tools/python/xen/xm/messages/en/xen-xm.po diff --git a/tools/python/Makefile b/tools/python/Makefile index 6b84446ee6..3732c06aa9 100644 --- a/tools/python/Makefile +++ b/tools/python/Makefile @@ -7,16 +7,26 @@ all: build .PHONY: build build: CC="$(CC)" CFLAGS="$(CFLAGS)" python setup.py build + for file in `cd xen/xm; find messages -name xen-xm.po`; do \ + dest=`echo "build/$$file" | \ + sed -e 's#xen-xm.po#LC_MESSAGES/xen-xm.mo#'`; \ + mkdir -p `dirname "$$dest"`; \ + msgfmt -c -o "$$dest" "xen/xm/$$file"; \ + done .PHONY: install ifndef XEN_PYTHON_NATIVE_INSTALL -install: all +install: install-messages CC="$(CC)" CFLAGS="$(CFLAGS)" python setup.py install --home="$(DESTDIR)/usr" --prefix="" --force else -install: all +install: install-messages CC="$(CC)" CFLAGS="$(CFLAGS)" python setup.py install --root="$(DESTDIR)" --force endif +install-messages: all + mkdir -p "$(DESTDIR)/usr/share/locale" + cp -R build/messages/* "$(DESTDIR)/usr/share/locale/" + .PHONY: test test: export LD_LIBRARY_PATH=$$(readlink -f ../libxc):$$(readlink -f ../xenstore); python test.py -b -u diff --git a/tools/python/xen/xm/XenAPI.py b/tools/python/xen/xm/XenAPI.py index cd794087c3..c2a9d0ce33 100644 --- a/tools/python/xen/xm/XenAPI.py +++ b/tools/python/xen/xm/XenAPI.py @@ -44,17 +44,32 @@ # OF THIS SOFTWARE. # -------------------------------------------------------------------- +import gettext import xmlrpclib import xen.util.xmlrpclib2 +gettext.install('xen-xm') + class Failure(Exception): def __init__(self, details): self.details = details def __str__(self): - return "Xen-API failure: %s" % str(self.details) + try: + return _(self.details[0]) % self._details_map() + except TypeError, exn: + return "Message database broken: %s.\nXen-API failure: %s" % \ + (exn, str(self.details)) + except Exception, exn: + import sys + print >>sys.stderr, exn + return "Xen-API failure: %s" % str(self.details) + + def _details_map(self): + return dict([(str(i), self.details[i]) + for i in range(len(self.details))]) class Session(xen.util.xmlrpclib2.ServerProxy): diff --git a/tools/python/xen/xm/main.py b/tools/python/xen/xm/main.py index 450d797354..5f27680a5e 100644 --- a/tools/python/xen/xm/main.py +++ b/tools/python/xen/xm/main.py @@ -1780,7 +1780,7 @@ def _run_cmd(cmd, cmd_name, args): except SystemExit, code: return code == 0, code except XenAPI.Failure, exn: - err(str(exn)) + print >>sys.stderr, str(exn) except xmlrpclib.Fault, ex: if ex.faultCode == XendClient.ERROR_INVALID_DOMAIN: err("Domain '%s' does not exist." % ex.faultString) diff --git a/tools/python/xen/xm/messages/en/xen-xm.po b/tools/python/xen/xm/messages/en/xen-xm.po new file mode 100644 index 0000000000..75d7f5e6fc --- /dev/null +++ b/tools/python/xen/xm/messages/en/xen-xm.po @@ -0,0 +1,67 @@ +# ============================================================================ +# This library is free software; you can redistribute it and/or +# modify it under the terms of version 2.1 of the GNU Lesser General Public +# License as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# ============================================================================ +# Copyright (c) 2006 XenSource Inc. +# ============================================================================ +# +# +msgid "" +msgstr "" +"Project-Id-Version: Xen-xm 3.0\n" +"PO-Revision-Date: 2006-12-23 11:04+0000\n" +"Last-Translator: Ewan Mellor \n" +"Language-Team: xen-devel \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=ASCII\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "INTERNAL_ERROR" +msgstr "Internal error: %(1)s." + +msgid "MAP_DUPLICATE_KEY" +msgstr "This map already contains %(1)s -> %(2)s." + +msgid "MESSAGE_METHOD_UNKNOWN" +msgstr "The method %(1)s is unsupported." + +msgid "MESSAGE_PARAMETER_COUNT_MISMATCH" +msgstr "The method %(1)s takes %(2)s argument(s) (%(3)s given)." + +msgid "SESSION_AUTHENTICATION_FAILED" +msgstr "Permission denied." + +msgid "HOST_CPU_HANDLE_INVALID" +msgstr "The host_cpu handle %(1)s is invalid." + +msgid "HOST_HANDLE_INVALID" +msgstr "The host handle %(1)s is invalid." + +msgid "SR_HANDLE_INVALID" +msgstr "The SR handle %(1)s is invalid." + +msgid "VBD_HANDLE_INVALID" +msgstr "The VBD handle %(1)s is invalid." + +msgid "VDI_HANDLE_INVALID" +msgstr "The VDI handle %(1)s is invalid." + +msgid "VIF_HANDLE_INVALID" +msgstr "The VIF handle %(1)s is invalid." + +msgid "VM_HANDLE_INVALID" +msgstr "The VM handle %(1)s is invalid." + +msgid "VTPM_HANDLE_INVALID" +msgstr "The VTPM handle %(1)s is invalid." + -- 2.30.2